package com.dd;

import com.chantel.tool.db.DBUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CaiGouGongSiBaoJiaXinXi {
	//id
	private int id;
	//采购商品id
	private int caiGouShangPingId;
	//公司ID
	private int gongSiId;
	//报价
	private String baoJia;
	//审核价
	private String shenHeJia; 
	
	public CaiGouGongSiBaoJiaXinXi()
	{
		
	}
	
	public CaiGouGongSiBaoJiaXinXi(int id, int caiGouShangPingId, int gongSiId, String baoJia, String shenHeJia)
	{
		super();
		
		this.id = id;
		this.caiGouShangPingId = caiGouShangPingId;
		this.gongSiId = gongSiId;
		this.baoJia = baoJia;
		this.shenHeJia = shenHeJia;
	}
	
	public int getGongSiId() {
		return gongSiId;
	}

	public void setGongSiId(int gongSiId) {
		this.gongSiId = gongSiId;
	}
	
	public int getCaiGouShangPingId() {
		return caiGouShangPingId;
	}

	public void setCaiGouShangPingId(int caiGouShangPingId) {
		this.caiGouShangPingId = caiGouShangPingId;
	}
	
	public void PutData(Map m)
	{
	    m.put("BaoJia", this.baoJia);
	    m.put("ShenHeJia", this.shenHeJia);	
	}
	
	/**
	 * 执行数据插入 TOD0 error handling 为保证数据完整性，必须在一个事务中处理
	 */
	public boolean Insert() {
		// TODO 执行数据插入
		DBUtil du = DBUtil.getInstance();
		Map m = new HashMap();
		
		PutData(m);
		m.put("GongSiId", new Integer(this.gongSiId));
		m.put("CaiGouShangPingId", new Integer(this.caiGouShangPingId));

		// do action
		boolean bool_res = du.insertRecord("CaiGouGongSiBaoJiaXinXiTable", m);
		return bool_res;
	}

	// 执行数据更新
	/**
	 * 为保证数据完整性，必须在一个事务中处理
	 */
	public boolean Update() {
		// TODO 执行数据更新
		DBUtil du = DBUtil.getInstance();
		Map m = new HashMap();

	    PutData(m);

		String updateWhere = "CaiGouShangPingId=" + this.caiGouShangPingId + " and GongSiId=" + this.gongSiId;
		
		boolean bool_res = du.updateFieldsValue("CaiGouGongSiBaoJiaXinXiTable", m,
				updateWhere);
		
		return bool_res;
	}
	
	public static List GetRecordsFromGongSiId(int gongSiId)
	{
		DBUtil du = DBUtil.getInstance();
		
		String sql = "select* from CaiGouGongSiBaoJiaXinXiTable where GongSiId =" + gongSiId;
		List l = du.getRecords(sql);	
		
		return l;
	}
	
	
	public static List GetRecordsFromCaiGouShangPingId(int shangPingId)
	{
		DBUtil du = DBUtil.getInstance();
		
		String sql = "select* from CaiGouGongSiBaoJiaXinXiTable where CaiGouShangPingId =" + shangPingId;
		List l = du.getRecords(sql);	
		
		return l;
	}

	//执行数据删除
	public static boolean  DeleteFromGongsiId(int gongSiId){
		//TODO 执行数据删除
		DBUtil du = DBUtil.getInstance();
		
		String sql = "delete from CaiGouGongSiBaoJiaXinXiTable where GongSiId=" + gongSiId;
		
		boolean bool_res = du.deleteRecords(sql);
		
		return bool_res;


	}
	
	public static boolean  DeleteFromShangPingId(int shangPingId)
	{
		//TODO 执行数据删除
		DBUtil du = DBUtil.getInstance();
		
		String sql = "delete from CaiGouGongSiBaoJiaXinXiTable where CaiGouShangPingId=" + shangPingId;
		
		boolean bool_res = du.deleteRecords(sql);
		
		return bool_res;
	}
}
